<template>
	<view class="container">
		<u--form ref="queryForm" :model="query" label-width="140rpx">
		  <u-form-item label="载具码" prop="containerCode">
		    <u--input
		    	placeholder="请输入/扫描"
		    	v-model.trim="query.containerCode"
		    	suffixIcon="scan" 
		    	suffixIconStyle="font-size: 68rpx"
		    	style="flex: 1;"
		    >
		    </u--input>
			</u-form-item>
			<u-form-item label="储位码" prop="storageCode">
		    <u--input
		    	placeholder="请输入/扫描"
		    	v-model.trim="query.storageCode"
		    	suffixIcon="scan" 
		    	suffixIconStyle="font-size: 68rpx"
		    	style="flex: 1;"
		    >
		    </u--input>
			</u-form-item>
		</u--form>
		<u-toast ref="uToast"></u-toast>
		<view class="commonButton">
			<u-button type="primary" :disabled="!query.storageCode || !query.containerCode" @click="storageBind">绑定</u-button>
			<u-button type="error" :disabled="!query.storageCode || !query.containerCode" @click="storageClear">解绑</u-button>
			<u-button type="warning" @click="reset">重置</u-button>
		</view>
	</view>
</template>

<script>
	import { storageClearAPI, storageBindAPI } from '@/api/work/usageAPIList.js'
	export default {
		data() {
			return {
				query: {
					storageCode: '',
					containerCode: ''
				}
			};
		},
		methods: {
			reset() {
				this.query = {
					storageCode: '',
					containerCode: ''
				}
			},
			async storageBind() {
				const res = await storageBindAPI(this.query)
				if (res.returnCode === '1') {
					this.reset()
					this.$refs.uToast.show({
						type: 'success',
						message: res.returnReason || '绑定成功'
					})
				} else {
					return this.$refs.uToast.show({
						type: 'warning',
						message: res.returnReason || '绑定失败'
					})
				}
			},
			async storageClear() {
				const res = await storageClearAPI(this.query)
				if (res.returnCode === '1') {
					this.reset()
					this.$refs.uToast.show({
						type: 'success',
						message: res.returnReason || '解绑成功'
					})
				} else {
					return this.$refs.uToast.show({
						type: 'warning',
						message: res.returnReason || '解绑失败'
					})
				}
			}
		}
	}
</script>

<style lang="scss">
.commonButton {
	width: 100%;
	display: flex;
	gap: 20rpx;
	position: fixed;
	left: 0;
	bottom: 0;
	box-sizing: border-box;
	padding: 15rpx;justify-content: space-between;
	background-color: #fff;
}
</style>
